package com.genshang.restaurant.controller;


import com.genshang.restaurant.result.ResultBody;
import com.genshang.restaurant.util.QiNiuOSSUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.Map;

@RestController
@RequestMapping("/picture")
public class PictureController {

    @Autowired
    private QiNiuOSSUtil ossUtil;

    @PostMapping(value = "/uploadPicture")
    public ResultBody uploadPicture(@RequestParam("uploadFile") MultipartFile uploadFile) {
        Map<String, Object> result = ossUtil.uploadPicture(uploadFile);
        if (result.get("success").equals("0")) {
            return ResultBody.error(result.get("message").toString());
        }
        return ResultBody.success(result.get("message").toString());
    }


}
